###########################################################################
# $Id: conceptFieldConverterBase.p 28 2009-05-09 08:25:28Z donbeave $
###########################################################################

@CLASS
conceptFieldConverterBase

@USE
concept/converters/conceptFieldConverter.p

@BASE
conceptFieldConverter

@OPTIONS
locals

#----- Constructor -----

@create[hshOptions]
## hshOptions.type[int/double/bool]
## hshOptions.defaultValue
  ^BASE:create[$hshOptions]

  $self._type[$_createOptions.type]
  $self._defaultValue[$_createOptions.defaultValue]

#----- Public -----

@onSelect[altData]
  ^switch[$self._type]{
    ^case[int]{
      ^if(def $self._defaultValue){
        $result(^altData.int($self._defaultValue))
      }{
         $result(^altData.int[])
       }
    }
    ^case[double]{
      ^if(def $self._defaultValue){
        $result(^altData.double($self._defaultValue))
      }{
         $result(^altData.double[])
      }
    }
    ^case[bool]{
      ^if(def $self._defaultValue){
        $result(^altData.bool($self._defaultValue))
      }{
         $result(^altData.bool[])
       }
    }
  }

@onUpdate[altData]
  $result[^onSelect[$altData]]

  ^if($result is bool){
    $result[^result.int[]]
  }
